package study.lxy.spring.springboot2.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class PrintTimeTask {
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private static final Logger logger = LoggerFactory.getLogger(PrintTimeTask.class);

    @Scheduled(cron = "0 0/5 * * * *")
    public void printTime(){
        logger.info("current time is {}",dateFormat.format(new Date()));
    }
}
